package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.clqteam.model.Employee;
import com.clqteam.service.EmployeeLoginService;
import com.clqteam.service.SelectEmployeeService;
import com.clqteam.serviceimpl.EmployeeLoginServiceImpl;
import com.clqteam.serviceimpl.SelectEmployeeServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * @author CLQ
 *
 */

public class SelectEmployeeController extends HttpServlet{
    SelectEmployeeService seService=new SelectEmployeeServiceImpl();
    //调用添加日志的service
    EmployeeLoginService emService =new EmployeeLoginServiceImpl();
    
	  @Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	  @Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		String InEmployee=req.getParameter("val");
		int page=Integer.parseInt(req.getParameter("page"));
		int rows=Integer.parseInt(req.getParameter("rows"));
		  JSONObject js= seService.findEmployeeInfo(InEmployee, page, rows);
			PrintWriter pw = resp.getWriter();
			pw.write(js.toString());
			//添加日志
			HttpSession session=req.getSession();
			Employee emp=(Employee)session.getAttribute("employee");
			  SimpleDateFormat sd=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
			  Date date=new Date();
			  String time=sd.format(date);
			  String info="查询了员工信息";
			  emService.insertLoginTime(time, info, emp.geteId(),emp.geteName());
			  //关闭输出流
			 pw.flush();
			 pw.close();
	}
}
